package com.whiteape.book.model.gen;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.whiteape.book.model.type.HomePageLayoutType;
import com.whiteape.book.utils.HomepageLayoutTypeConverter;
import com.whiteape.book.utils.MapConverter;
import java.util.HashMap;

import com.whiteape.book.model.bo.CategoryDetailBo;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "CATEGORY_DETAIL_BO".
*/
public class CategoryDetailBoDao extends AbstractDao<CategoryDetailBo, String> {

    public static final String TABLENAME = "CATEGORY_DETAIL_BO";

    /**
     * Properties of entity CategoryDetailBo.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property DetailUrl = new Property(0, String.class, "detailUrl", true, "DETAIL_URL");
        public final static Property NextPage = new Property(1, String.class, "nextPage", false, "NEXT_PAGE");
        public final static Property VarMap = new Property(2, String.class, "varMap", false, "VAR_MAP");
        public final static Property CategoryUrl = new Property(3, String.class, "categoryUrl", false, "CATEGORY_URL");
        public final static Property HomePageShowType = new Property(4, String.class, "homePageShowType", false, "HOME_PAGE_SHOW_TYPE");
        public final static Property MediaType = new Property(5, Integer.class, "mediaType", false, "MEDIA_TYPE");
        public final static Property Title = new Property(6, String.class, "title", false, "TITLE");
        public final static Property Author = new Property(7, String.class, "author", false, "AUTHOR");
        public final static Property CoverUrl = new Property(8, String.class, "coverUrl", false, "COVER_URL");
        public final static Property Desc = new Property(9, String.class, "desc", false, "DESC");
        public final static Property WordCount = new Property(10, String.class, "wordCount", false, "WORD_COUNT");
        public final static Property State = new Property(11, String.class, "state", false, "STATE");
        public final static Property Category = new Property(12, String.class, "category", false, "CATEGORY");
        public final static Property LastChapter = new Property(13, String.class, "lastChapter", false, "LAST_CHAPTER");
        public final static Property LastUpdated = new Property(14, String.class, "lastUpdated", false, "LAST_UPDATED");
    }

    private final MapConverter varMapConverter = new MapConverter();
    private final HomepageLayoutTypeConverter homePageShowTypeConverter = new HomepageLayoutTypeConverter();
    private Query<CategoryDetailBo> siteSourceCategoryBean_CategoryDetailBoListQuery;

    public CategoryDetailBoDao(DaoConfig config) {
        super(config);
    }
    
    public CategoryDetailBoDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"CATEGORY_DETAIL_BO\" (" + //
                "\"DETAIL_URL\" TEXT PRIMARY KEY NOT NULL ," + // 0: detailUrl
                "\"NEXT_PAGE\" TEXT," + // 1: nextPage
                "\"VAR_MAP\" TEXT," + // 2: varMap
                "\"CATEGORY_URL\" TEXT," + // 3: categoryUrl
                "\"HOME_PAGE_SHOW_TYPE\" TEXT," + // 4: homePageShowType
                "\"MEDIA_TYPE\" INTEGER," + // 5: mediaType
                "\"TITLE\" TEXT," + // 6: title
                "\"AUTHOR\" TEXT," + // 7: author
                "\"COVER_URL\" TEXT," + // 8: coverUrl
                "\"DESC\" TEXT," + // 9: desc
                "\"WORD_COUNT\" TEXT," + // 10: wordCount
                "\"STATE\" TEXT," + // 11: state
                "\"CATEGORY\" TEXT," + // 12: category
                "\"LAST_CHAPTER\" TEXT," + // 13: lastChapter
                "\"LAST_UPDATED\" TEXT);"); // 14: lastUpdated
        // Add Indexes
        db.execSQL("CREATE INDEX " + constraint + "IDX_CATEGORY_DETAIL_BO_CATEGORY_URL ON \"CATEGORY_DETAIL_BO\"" +
                " (\"CATEGORY_URL\" ASC);");
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"CATEGORY_DETAIL_BO\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, CategoryDetailBo entity) {
        stmt.clearBindings();
 
        String detailUrl = entity.getDetailUrl();
        if (detailUrl != null) {
            stmt.bindString(1, detailUrl);
        }
 
        String nextPage = entity.getNextPage();
        if (nextPage != null) {
            stmt.bindString(2, nextPage);
        }
 
        HashMap varMap = entity.getVarMap();
        if (varMap != null) {
            stmt.bindString(3, varMapConverter.convertToDatabaseValue(varMap));
        }
 
        String categoryUrl = entity.getCategoryUrl();
        if (categoryUrl != null) {
            stmt.bindString(4, categoryUrl);
        }
 
        HomePageLayoutType homePageShowType = entity.getHomePageShowType();
        if (homePageShowType != null) {
            stmt.bindString(5, homePageShowTypeConverter.convertToDatabaseValue(homePageShowType));
        }
 
        Integer mediaType = entity.getMediaType();
        if (mediaType != null) {
            stmt.bindLong(6, mediaType);
        }
 
        String title = entity.getTitle();
        if (title != null) {
            stmt.bindString(7, title);
        }
 
        String author = entity.getAuthor();
        if (author != null) {
            stmt.bindString(8, author);
        }
 
        String coverUrl = entity.getCoverUrl();
        if (coverUrl != null) {
            stmt.bindString(9, coverUrl);
        }
 
        String desc = entity.getDesc();
        if (desc != null) {
            stmt.bindString(10, desc);
        }
 
        String wordCount = entity.getWordCount();
        if (wordCount != null) {
            stmt.bindString(11, wordCount);
        }
 
        String state = entity.getState();
        if (state != null) {
            stmt.bindString(12, state);
        }
 
        String category = entity.getCategory();
        if (category != null) {
            stmt.bindString(13, category);
        }
 
        String lastChapter = entity.getLastChapter();
        if (lastChapter != null) {
            stmt.bindString(14, lastChapter);
        }
 
        String lastUpdated = entity.getLastUpdated();
        if (lastUpdated != null) {
            stmt.bindString(15, lastUpdated);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, CategoryDetailBo entity) {
        stmt.clearBindings();
 
        String detailUrl = entity.getDetailUrl();
        if (detailUrl != null) {
            stmt.bindString(1, detailUrl);
        }
 
        String nextPage = entity.getNextPage();
        if (nextPage != null) {
            stmt.bindString(2, nextPage);
        }
 
        HashMap varMap = entity.getVarMap();
        if (varMap != null) {
            stmt.bindString(3, varMapConverter.convertToDatabaseValue(varMap));
        }
 
        String categoryUrl = entity.getCategoryUrl();
        if (categoryUrl != null) {
            stmt.bindString(4, categoryUrl);
        }
 
        HomePageLayoutType homePageShowType = entity.getHomePageShowType();
        if (homePageShowType != null) {
            stmt.bindString(5, homePageShowTypeConverter.convertToDatabaseValue(homePageShowType));
        }
 
        Integer mediaType = entity.getMediaType();
        if (mediaType != null) {
            stmt.bindLong(6, mediaType);
        }
 
        String title = entity.getTitle();
        if (title != null) {
            stmt.bindString(7, title);
        }
 
        String author = entity.getAuthor();
        if (author != null) {
            stmt.bindString(8, author);
        }
 
        String coverUrl = entity.getCoverUrl();
        if (coverUrl != null) {
            stmt.bindString(9, coverUrl);
        }
 
        String desc = entity.getDesc();
        if (desc != null) {
            stmt.bindString(10, desc);
        }
 
        String wordCount = entity.getWordCount();
        if (wordCount != null) {
            stmt.bindString(11, wordCount);
        }
 
        String state = entity.getState();
        if (state != null) {
            stmt.bindString(12, state);
        }
 
        String category = entity.getCategory();
        if (category != null) {
            stmt.bindString(13, category);
        }
 
        String lastChapter = entity.getLastChapter();
        if (lastChapter != null) {
            stmt.bindString(14, lastChapter);
        }
 
        String lastUpdated = entity.getLastUpdated();
        if (lastUpdated != null) {
            stmt.bindString(15, lastUpdated);
        }
    }

    @Override
    public String readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0);
    }    

    @Override
    public CategoryDetailBo readEntity(Cursor cursor, int offset) {
        CategoryDetailBo entity = new CategoryDetailBo( //
            cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // detailUrl
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // nextPage
            cursor.isNull(offset + 2) ? null : varMapConverter.convertToEntityProperty(cursor.getString(offset + 2)), // varMap
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // categoryUrl
            cursor.isNull(offset + 4) ? null : homePageShowTypeConverter.convertToEntityProperty(cursor.getString(offset + 4)), // homePageShowType
            cursor.isNull(offset + 5) ? null : cursor.getInt(offset + 5), // mediaType
            cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // title
            cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // author
            cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // coverUrl
            cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // desc
            cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // wordCount
            cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11), // state
            cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12), // category
            cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13), // lastChapter
            cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14) // lastUpdated
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, CategoryDetailBo entity, int offset) {
        entity.setDetailUrl(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
        entity.setNextPage(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setVarMap(cursor.isNull(offset + 2) ? null : varMapConverter.convertToEntityProperty(cursor.getString(offset + 2)));
        entity.setCategoryUrl(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setHomePageShowType(cursor.isNull(offset + 4) ? null : homePageShowTypeConverter.convertToEntityProperty(cursor.getString(offset + 4)));
        entity.setMediaType(cursor.isNull(offset + 5) ? null : cursor.getInt(offset + 5));
        entity.setTitle(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
        entity.setAuthor(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
        entity.setCoverUrl(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8));
        entity.setDesc(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9));
        entity.setWordCount(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10));
        entity.setState(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11));
        entity.setCategory(cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12));
        entity.setLastChapter(cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13));
        entity.setLastUpdated(cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14));
     }
    
    @Override
    protected final String updateKeyAfterInsert(CategoryDetailBo entity, long rowId) {
        return entity.getDetailUrl();
    }
    
    @Override
    public String getKey(CategoryDetailBo entity) {
        if(entity != null) {
            return entity.getDetailUrl();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(CategoryDetailBo entity) {
        return entity.getDetailUrl() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "categoryDetailBoList" to-many relationship of SiteSourceCategoryBean. */
    public List<CategoryDetailBo> _querySiteSourceCategoryBean_CategoryDetailBoList(String categoryUrl) {
        synchronized (this) {
            if (siteSourceCategoryBean_CategoryDetailBoListQuery == null) {
                QueryBuilder<CategoryDetailBo> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.CategoryUrl.eq(null));
                siteSourceCategoryBean_CategoryDetailBoListQuery = queryBuilder.build();
            }
        }
        Query<CategoryDetailBo> query = siteSourceCategoryBean_CategoryDetailBoListQuery.forCurrentThread();
        query.setParameter(0, categoryUrl);
        return query.list();
    }

}
